﻿using System;
namespace Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="KARRParing", Namespace="http://producers.etoimik.xtee.riik.ee/producer/etoimik", Target=typeof(KARRParing))]
    public class KARRParingSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IKARRParing clazz;
        
        public KARRParingSerializer(IKARRParing clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.Isik!=null) {
                Writer.WriteStartElement("Isik");
                global::Xtee.Core.SerializationMetadata metaIsik = this.GetMetaData(clazz.Isik);
                Writer.WriteTypeAttribute(metaIsik.TypeQualifiedName.Namespace, metaIsik.TypeQualifiedName.Name);
                metaIsik.NewSerializer(clazz.Isik).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.Aeg!=null) {
                Writer.WriteStartElement("Aeg");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.Aeg))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Infosysteem!=null) {
                Writer.WriteStartElement("Infosysteem");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Infosysteem))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.LiikKL!=null) {
                Writer.WriteStartElement("LiikKL");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.LiikKL))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Pohjendus!=null) {
                Writer.WriteStartElement("Pohjendus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Pohjendus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.EesmarkKL!=null) {
                Writer.WriteStartElement("EesmarkKL");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.EesmarkKL))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Isik") {
                if ((Reader.IsElementNil() == false)) {
                    global::Xtee.Core.SerializationMetadata metaIsik = this.GetMetaData<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IIsik>(Reader, "Isik", "http://producers.etoimik.xtee.riik.ee/producer/etoimik");
                    clazz.Isik = metaIsik.NewEntity<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IIsik>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("Isik");
                        metaIsik.NewSerializer(clazz.Isik).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Aeg") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>KARRParing>Aeg");
                }
                clazz.Aeg = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("Aeg")).Value;
            }
            if (Reader.LocalName=="Infosysteem") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Infosysteem = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Infosysteem")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="LiikKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.LiikKL = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("LiikKL")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Pohjendus") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Pohjendus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Pohjendus")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="EesmarkKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.EesmarkKL = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("EesmarkKL")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
